#include<bits/stdc++.h>
using namespace std;
#define int long long

int a[100];
string s[100];

signed main() {
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> a[i] >> s[i];

	for (int i = 1; i <= n; i++) {
		if (a[i] < 0)
			continue;

		int j;
		for (j = n; a[i] + a[j] != 1; j--);
		a[j] = -1;

		cout << s[i] << " " << s[j] << endl;
	}
	return 0;
}
